package com.itcat.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itcat.common.CommonPage;
import com.itcat.common.CommonResult;
import com.itcat.mysql.pojo.SmsHomeNewProduct;
import com.itcat.mysql.pojo.SmsHomeRecommendProduct;
import com.itcat.service.SmsHomeRecommendProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


//人气推荐
import java.util.List;

@RestController
@RequestMapping("/home/recommendProduct")
public class SmsHomeRecommendProductController {

    @Autowired
    private SmsHomeRecommendProductService recommendProductService;

    //分页查询推荐
    @RequestMapping("/list")
    @ResponseBody
    public CommonResult<CommonPage<SmsHomeRecommendProduct>> list(String productName,
                                                                  Integer recommendStatus,
                                                                  @RequestParam Integer pageSize,
                                                                  @RequestParam Integer pageNum) {
        Page<SmsHomeRecommendProduct> homeRecommendProductList = recommendProductService.list(productName, recommendStatus, pageSize, pageNum);
        return CommonResult.success(CommonPage.restPage(homeRecommendProductList));
    }

    //添加
    @PostMapping("/create")
    public CommonResult create(@RequestBody List<SmsHomeRecommendProduct> smsHomeRecommendProducts) {
        recommendProductService.create(smsHomeRecommendProducts);
        return CommonResult.success();
    }

    //删除新品
    @PostMapping("/delete")
    public CommonResult delete(@RequestParam List<Integer> ids) {
        recommendProductService.delete(ids);
        return CommonResult.success();
    }

    //修改是否推荐
    @PostMapping("/update/recommendStatus")
    public CommonResult updateRecommendStatus(@RequestParam List<Integer> ids,
                                              @RequestParam Integer recommendStatus) {
        recommendProductService.updateRecommendStatus(ids, recommendStatus);
        return CommonResult.success();

    }

    //修改推荐品牌排序
    @PostMapping("/update/sort/{id}")
    public CommonResult updateSort(@PathVariable Integer id,
                                   @RequestParam Integer sort) {
        recommendProductService.updateSort(id, sort);
        return CommonResult.success();
    }
}